<template>
	<div>
		<!-- <so-header :seller="headerTitle"></so-header> -->
    <setHeader :title="headerTitle"></setHeader>
    <div class="pagecontent">
        <h3 class="mt-notice" style="color: #e50838; text-align: left;">该企业已存在，欢迎您成为该企业管理员</h3>
        <div class="write_input_box write-label">
            <label for="">企业名称：</label>
            <input type="text" placeholder="请输入企业名称" v-model="companyName" @mousedown="showPicker">
        </div>
        <div class="write_input_box write-label">
            <label for="">管理人姓名：</label>
            <input type="text" placeholder="请输入您的真实姓名" v-model="username">
        </div>
        <div class="write_input_box write-label" style="border-bottom: none;">
            <label for="">管理人职位：</label>
            <input type="text" placeholder="请输入管理人的职位" v-model="job">
        </div>
        <div class="btn_big_red" @click="NextStep" style="margin-top: 0.9rem;">
            <button>完成</button>
        </div>
    </div>
		<!-- <h3 class="mt-notice">该企业已存在，欢迎您成为该企业管理员</h3>
		<mt-field label="企业名称" placeholder=""  v-model="companyName" @mousedown.native="showPicker"></mt-field>
    	<mt-field label="管理员姓名" placeholder="请输入管理员名称"  v-model="username"></mt-field>
   
    	<mt-field label="管理员职位" placeholder="请输入您的职位"  v-model="job"></mt-field>
		<mt-button type="default" class="el-long-button"  @click="NextStep">完成</mt-button> -->
	</div>
</template>
<script>
import setHeader from '../public/setHeader.vue';
import { MessageBox } from 'mint-ui';


export default {
	data() {
      return {
      	headerTitle:'企业资料',
        companyName: '',
        username:'',
        job:'',
        userInfo:'',
        uid: ''
      };
    },
    components:{
    	setHeader,
    },
    created() {
        let that = this;
        that.userInfo = window.localStorage.getItem('userInfo');
        that.userInfo = JSON.parse(that.userInfo);
        that.uid = that.userInfo.uid;
    },
    mounted() {
      // let that = this;
      // var user = Promise.resolve(this.getUserInfo())
      // user.then(
      //   function (result) { 
      //   that.userInfo = result;
      //   that.uid = result.uid;
      // })

      this.companyName = this.$route.query.companyName;
      this.cpId = window.localStorage.getItem('paicheNo');
    },
    methods:{
    	NextStep:function(){
    		let that = this;
    		let companyName = that.companyName;
        let adminName = that.username;
        let adminJob = that.job;
        let userId = that.uid;

        if(adminName == '' || adminName == undefined){
          MessageBox('温馨提示', '请输入管理员名称');
          return false;
        }
    		if(adminJob == '' || adminJob == undefined){
    			MessageBox('温馨提示', '请输入您的职位');
          return false;
    		}else{

    	//提交成为管理员
      that.$fetch(that.$path + '/api.php/company/applyByCompanyAdmin', {userId, companyName, adminName, adminJob}).then((response) => {
              if(response.code != 200){
                MessageBox('温馨提示', response.msg);
                return false;
              }else{

              that.userInfo = window.localStorage.getItem('userInfo');
              that.userInfo = JSON.parse(that.userInfo);
              that.userInfo.position     = response.data.company.position;    //职位
              that.userInfo.industry     = response.data.company.industry;    //行业
              that.userInfo.company      = response.data.c_id;    //职位
              let userInfo = JSON.stringify(that.userInfo);
              window.localStorage.setItem('userInfo',userInfo);
              
                MessageBox.alert(response.msg).then(action => {
                  that.$router.push({path: '/userCenter/companyData', query: {cpId: userId}})
                }); 
              } 
            })
    		}
    	},
      
      showPicker(e){
        e.preventDefault(); //阻止输入法的唤醒
      },
     
    }
}

</script>

<style >
.el-long-button{
	margin-top:50px;
}
/* p{
  font-size: 16px;
  font-weight: bold;
} */
.mint-field{
  border-bottom: #f4f5f7 solid 1px;
}
.mint-popup{
  width:100%;
}
.mint-popup ul{
  width:100%;
  margin:0;
  padding:0;
  font-size: 0.34rem;
  color: #333;
}
.mint-popup ul li{
  float:left;
  width:100%;
  line-height:30px;
  text-align:center;
  margin-bottom:10px;
}

/* 该企业已存在 */
.mt-notice{
  /* height: 1.1rem ; */
  line-height: 1.1rem ;
  font-size: 0.36rem ;
  padding: 0 0.2rem ;
  font-weight: 500;
  font-family:SourceHanSansCN-Medium;
}

/* 创建企业--完成 */
.write-label label{
  width: 1.8rem;
}
.write-label input {
  width: 72%;
}


</style>